home *** CD-ROM | disk | FTP | other *** search
/ Graphics & Sound Program…ng Techniques for the Mac / Graphics and Sound Programming Techniques for the Mac.iso / M&T Graphics & Sound Examples / Symantec Versions / C06 QuickDraw GX / P03 QD GX Windows / QDGXWindow.c next >
Encoding:
C/C++ Source or Header  |  1995-09-01  |  3.6 KB  |  158 lines  |  [TEXT/KAHL]

  1. //____________________________________________________________
  2. //    QDGXWindow.c
  3. //
  4. //    Copyright © Dan Parks Sydow, 1995
  5. //    From the book:
  6. //    "Graphics and Sound Programming Techniques for the Mac",
  7. //    M&T Books, 1995
  8.  
  9.  
  10. //____________________________________________________________
  11.  
  12. #include "PrintingManager.h"      // defines the Gestalt selector code gestaltGXPrintingMgrVersion
  13. #include "graphics macintosh.h"   // defines the Gestalt selector code gestaltGraphicsVersion
  14. #include "graphics toolbox.h"     // prototype for the GX function GXNewWindowViewPort()
  15. #include "graphics libraries.h"   // prototypes for several GX functions
  16.  
  17.  
  18. //____________________________________________________________
  19.  
  20. Boolean  IsQuickDrawGXAvailable( void );
  21. void     InitializeToolbox( void );
  22. void     InitializeQuickDrawGX( void );
  23. void     OpenDisplayWindow( void );
  24. void     CleanUpQuickDrawGXandQuit( void );
  25.  
  26.  
  27. //____________________________________________________________
  28.  
  29. #define     kGXClientHeapSizeBytes    150 * 1024
  30.  
  31.  
  32. //____________________________________________________________
  33.  
  34. gxGraphicsClient  gGXClient;
  35. Boolean           gQuickDrawGXPresent;
  36. WindowPtr         gDisplayWindow = nil;
  37. gxViewPort        gWindowViewPort;
  38. Boolean           gDone = false;
  39.  
  40.  
  41. //____________________________________________________________
  42.  
  43. void  main( void )
  44. {
  45.    InitializeToolbox();
  46.  
  47.    gQuickDrawGXPresent = IsQuickDrawGXAvailable();
  48.    if ( gQuickDrawGXPresent == true )
  49.       InitializeQuickDrawGX();
  50.    else
  51.       ExitToShell();
  52.  
  53.    OpenDisplayWindow();
  54.  
  55.    while ( gDone == false )
  56.    {
  57.       if ( Button() )
  58.          CleanUpQuickDrawGXandQuit();
  59.    }      
  60. }
  61.  
  62.  
  63. //____________________________________________________________
  64.  
  65. Boolean  IsQuickDrawGXAvailable( void )
  66. {
  67.    OSErr  theError;
  68.    long   theResult;
  69.    
  70.    theError = Gestalt( gestaltGraphicsVersion, &theResult );
  71.    if ( theError != noErr )
  72.       return ( false );
  73.  
  74.    theError = Gestalt( gestaltGXPrintingMgrVersion, &theResult );
  75.    if ( theError != noErr )
  76.       return ( false );
  77.       
  78.    return ( true );
  79. }
  80.  
  81.  
  82. //____________________________________________________________
  83.  
  84. void  InitializeQuickDrawGX( void )
  85. {
  86.    gxGraphicsError  theGXgraphicsError;
  87.    OSErr            theGXprintError;      
  88.    
  89.    gGXClient = GXNewGraphicsClient( nil, kGXClientHeapSizeBytes, 0L );
  90.  
  91.    GXEnterGraphics();
  92.    theGXgraphicsError = GXGetGraphicsError( nil );
  93.    if ( theGXgraphicsError == out_of_memory )
  94.       ExitToShell();
  95.  
  96.    theGXprintError = GXInitPrinting();
  97.    if ( theGXprintError != noErr )
  98.       ExitToShell();
  99. }
  100.  
  101.  
  102. //____________________________________________________________
  103.  
  104. void  OpenDisplayWindow( void )
  105. {
  106.    gDisplayWindow = GetNewCWindow( 128, nil, (WindowPtr)-1L ); 
  107.    ShowWindow( gDisplayWindow );
  108.    SetPort( gDisplayWindow );
  109.    MoveTo( 20, 20 );
  110.    DrawString( "\pReady for shapes!" );
  111.  
  112.    gWindowViewPort = GXNewWindowViewPort( gDisplayWindow );
  113.  
  114. // GXNewShape() - create a shape
  115.  
  116. // GXSetShapeViewPorts() - pair the shape with the view port
  117.  
  118. // GXDrawShape() - draw the shape
  119.    
  120. }
  121.  
  122.  
  123. //____________________________________________________________
  124.  
  125. void  CleanUpQuickDrawGXandQuit( void )
  126. {
  127.    OSErr  theGXprintError;      
  128.  
  129.    if ( gDisplayWindow != nil )
  130.    {
  131.       GXDisposeViewPort( gWindowViewPort );
  132.       DisposeWindow( gDisplayWindow );  
  133.    }
  134.    
  135.    theGXprintError = GXExitPrinting();
  136.  
  137.    GXExitGraphics();
  138.    
  139.    GXDisposeGraphicsClient( gGXClient ); 
  140.  
  141.    gDone = true;
  142. }
  143.  
  144.  
  145. //____________________________________________________________
  146.  
  147. void  InitializeToolbox( void )
  148. {
  149.    InitGraf( &qd.thePort );
  150.    InitFonts();
  151.    InitWindows();
  152.    InitMenus();
  153.    TEInit();
  154.    InitDialogs( 0L );
  155.    FlushEvents( everyEvent, 0 );
  156.    InitCursor();
  157. }
  158.